1634F - Fibonacci Additions - CodeForces Solution


brute force data structures hashing implementation math *2700

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#include <cstdio>
#define N 300010
#define ll long long
int n,q,cnt;
ll a[N],f[N],p; char s[5];
void add(int x,ll v) {if(x<=n&&v) cnt-=!a[x],cnt+=!((a[x]+=v+p)%=p);}
int main()  //main functionnnn
{
    scanf("%d%d%d",&n,&q,&p);
   f[1]=1;
    for(int i=2;i<=n;i++) 
   f[i]=(f[i-1]+f[i-2])%p;
    for(int i=1;i<=n;i++) 
      scanf("%d",a+i);
    for(int i=1,x;i<=n;i++) 
       scanf("%d",&x), (a[i]+=p-x)%=p;
    for(int i=n;i>1;i--) a[i]=((a[i]-a[i-1]-a[i-2])%p+p)%p;
    for(int i=1;i<=n;i++) cnt+=!a[i];
    for(int i=1,l,r;i<=q;i++)
    {
        scanf("%s%d%d",s,&l,&r);
        if(s[0]=='A') add(l,1),add(r+1,-f[r-l+2]),add(r+2,-f[r-l+1]);
        else add(l,-1),add(r+1,f[r-l+2]),add(r+2,f[r-l+1]);
        puts(cnt==n?"YES":"NO");
    }
} //fibooo

 						 			 			 				 		 	  	  	


Comments

Submit
0 Comments
More Questions

149A - Business trip
34A - Reconnaissance 2
59A - Word
462B - Appleman and Card Game
1560C - Infinity Table
1605C - Dominant Character
1399A - Remove Smallest
208A - Dubstep
1581A - CQXYM Count Permutations
337A - Puzzles
495A - Digital Counter
796A - Buying A House
67A - Partial Teacher
116A - Tram
1472B - Fair Division
1281C - Cut and Paste
141A - Amusing Joke
112A - Petya and Strings
677A - Vanya and Fence
1621A - Stable Arrangement of Rooks
472A - Design Tutorial Learn from Math
1368A - C+=
450A - Jzzhu and Children
546A - Soldier and Bananas
32B - Borze
1651B - Prove Him Wrong
381A - Sereja and Dima
41A - Translation
1559A - Mocha and Math
832A - Sasha and Sticks